package com.ifp.opengate.boot.decode.service;

import org.springframework.stereotype.Component;

import com.ifp.core.log.Trace;
import com.ifp.opengate.boot.decode.CryptoService;
import com.ifp.opengate.boot.utils.AESUtil;

/**
 * <p>
 * 字符串的AES解密
 * </P>
 *
 * @author zhuzh@belink.com
 * @version 0.0.1
 * @className AESDecodeServiceImpl
 * @sine 2020/4/23 14:36
 */
@Component
public class AESCryptoServiceImpl implements CryptoService {

    @Override
    public String decode(String encodeStr, String cipher, String field) throws Exception {
        Trace.logInfo(Trace.MODULE_FILTER, "AESDecodeServiceImpl start decode....");
        String decrypt = AESUtil.decrypt(encodeStr, cipher);
        Trace.logInfo(Trace.MODULE_FILTER, "AESDecodeServiceImpl end decode....{} decode is {}", field, decrypt);
        return decrypt;
    }

    @Override
    public String encode(String content, String cipher, String field) throws Exception {
        Trace.logInfo(Trace.MODULE_FILTER, "AESDecodeServiceImpl start encode....");
        String encrypt = AESUtil.encrypt(content, cipher);
        Trace.logInfo(Trace.MODULE_FILTER, "AESDecodeServiceImpl end decode....{} decode is {}", field, encrypt);
        return encrypt;
    }
}
